﻿namespace CommonUtilityInfrastructure.Tests
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using CommonUtilityInfrastructure;
    using NUnit.Framework;
    using SoftwareApproach.TestingExtensions;
    using UsefulTools.CheckboxedTree;
    using UsefulTools.ExtensionMethods;
    using Switch = UsefulTools.Switches.Switch;

    [TestFixture]
    public class CollectionsTests
    {
        

        [Test]
        public void SparseDict()
        {
            var numbers = Enumerable.Range(0, 4).Select(i => new {Number = i}).Repeat(1);
            var keySpace = new[] {2,1};

            var dict = numbers.ToSparseDictionary(keySpace, item => item.Number);

            dict.Count.ShouldEqual(2);
            dict.Keys.ShouldContain(1);
            dict.Keys.ShouldContain(2);

        }

        [Test]
        public void Repeat_2()
        {
            var numbers = Enumerable.Range(0, 3).Repeat(2);
            CollectionAssert.AreEqual(new[] { 0, 1, 2, 0, 1, 2, 0, 1, 2, }, numbers);
        }
        [Test]
        public void Repeat_0()
        {
            var numbers = Enumerable.Range(0, 3).Repeat(0).ToList();
            CollectionAssert.AreEqual(new[] { 0, 1, 2, }, numbers);
        }
        [Test]
        public void Pairs_Valid()
        {
            var pairs = Collections.Pairs<string, int>("a", 1, "b", 2);
            pairs.Count.ShouldEqual(2);
            pairs.ElementAt(0).ShouldEqual(Tuple.Create("a", 1));
            pairs.ElementAt(1).ShouldEqual(Tuple.Create("b", 2));
        }
        [Test,ExpectedException(typeof(InvalidCastException))]
        public void Pairs_Invalid_Type()
        {
            var pairs = Collections.Pairs<string, int>("a", 1, "b", "2");
            
        }
        [Test, ExpectedException(typeof(ArgumentException))]
        public void Pairs_Invalid_Count()
        {
            var pairs = Collections.Pairs<string, int>("a", 1, "b");

        }
    }
}

